import  {Page} from "@/utils/request"
import  {searchForm} from "./useSearch"
import {ref} from "vue";
import {getRoleList} from "@/api/system/role";
export interface Role {
    id: number;
    roleName: string;
    roleDesc: string;
    dataStatus: number;
    createTime: string;
    updateTime: string;
}
const tableData = ref<Role[]>([])
const tableLoading = ref(false)
const  total = ref(0)
export default function useTable() {
    function getRoleDataList() {
        tableLoading.value = true
        getRoleList(searchForm).then(res=>{
            const page = (res.data as Page<Role>)
            tableLoading.value =false
            tableData.value = page.list
            total.value = page.total
        })
    }
    function handleCurrentPageChange(val: number) {
        searchForm.page = val
        getRoleDataList()
    }
    function handlePageSizeChange(val: number) {
        searchForm.pageSize = val
        getRoleDataList()
    }
    return {
        getRoleDataList,
        tableData,
        tableLoading,
        total,
        handleCurrentPageChange,
        handlePageSizeChange
    }
}
